﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;

namespace ReverseEgns
{
    class ReverseEgns
    {
        public static string ReverseEGN(Match match)
        {
            string matchedEgn = match.Value;

            StringBuilder reversedEgn = new StringBuilder();

            for (int i = matchedEgn.Length-1; i >= 0; i--)
            {
                reversedEgn.Append(matchedEgn[i]);
            }
            return reversedEgn.ToString();
        }

        public static List<string> ExtractEgns(string filename , string outputFilename)
        {
            StreamReader inputFile = new StreamReader(filename);

            List<string> egns = new List<string>();
            string pattern = @"\b[0-9]{10}\b";
            Regex regex = new Regex(pattern);
            using (inputFile)
            {
                StreamWriter outputFile = new StreamWriter(outputFilename);
                using (outputFile)
                {
                    string line = inputFile.ReadLine();
                    while (line != null)
                    {
                        string currentLineWithReversedEGN = regex.Replace(line, ReverseEGN);
                        if (string.IsNullOrEmpty(currentLineWithReversedEGN) == false)
                        {
                            egns.Add(currentLineWithReversedEGN);
                        }
                        outputFile.WriteLine(currentLineWithReversedEGN);
                        line = inputFile.ReadLine();
                    }
                }
            }
            return egns;
        }

        static void Main(string[] args)
        {

        }
    }
}
